﻿using System.Configuration;
using System.Diagnostics.CodeAnalysis;

namespace BLL.Configuration.CDN
{
    /// <summary>
    /// CDN Collection for <see cref="CdnElement"/>  for web.config
    /// </summary>
    [SuppressMessage("Microsoft.Design", "CA1010:CollectionsShouldImplementGenericInterface")]
    public class CdnElementCollection : ConfigurationElementCollection
    {
        /// <summary>
        /// Gets or sets a property, attribute, or child element of this configuration element.
        /// </summary>
        /// <param name="index">Index</param>
        /// <returns>The specified property, attribute, or child element</returns>
        /// <exception cref="T:System.Configuration.ConfigurationErrorsException">
        /// <paramref /> is read-only or locked.</exception>
        public CdnElement this[int index]
        {
            get
            {
                return BaseGet(index) as CdnElement;
            }
            set
            {
                if (BaseGet(index) != null)
                {
                    BaseRemoveAt(index);
                }
                BaseAdd(index, value);
            }
        }

        /// <summary>
        /// When overridden in a derived class, creates a new
        /// <see cref="T:System.Configuration.ConfigurationElement"/>.
        /// </summary>
        /// <returns>
        /// A new <see cref="T:System.Configuration.ConfigurationElement"/>.
        /// </returns>
        protected override ConfigurationElement CreateNewElement()
        {
            return new CdnElement();
        }

        /// <summary>
        /// Gets the element key for a specified configuration element when overridden in a derived class.
        /// </summary>
        /// <param name="element">The <see cref="T:System.Configuration.ConfigurationElement"/>
        /// to return the key for.</param>
        /// <returns>
        /// An <see cref="T:System.Object"/> that acts as the key for the specified
        /// <see cref="T:System.Configuration.ConfigurationElement"/>.
        /// </returns>
        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((CdnElement)element).Name;
        }
    }
}